"""
简单的输入框组件测试
"""
import sys
import os

# 添加项目根目录到Python路径
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QLabel, QHBoxLayout, QGridLayout
from PyQt5.QtCore import Qt

from component.input import Input
from component.button import Button
from component.theme import Theme

class TestWindow(QMainWindow):
    """测试窗口"""
    
    def __init__(self):
        super().__init__()
        
        # 设置窗口属性
        self.setWindowTitle("输入框组件测试")
        self.resize(400, 300)
        
        # 创建中央部件
        central_widget = QWidget()
        self.setCentralWidget(central_widget)
        
        # 创建布局
        layout = QVBoxLayout(central_widget)
        layout.setContentsMargins(20, 20, 20, 20)
        layout.setSpacing(20)
        
        # 添加标题
        title = QLabel("输入框组件测试")
        title.setAlignment(Qt.AlignCenter)
        layout.addWidget(title)
        
        # 创建网格布局
        grid_widget = QWidget()
        grid_layout = QGridLayout(grid_widget)
        grid_layout.setContentsMargins(0, 0, 0, 0)
        grid_layout.setSpacing(10)
        
        # 添加输入框
        self.input1 = Input(label="用户名", placeholder="请输入用户名")
        self.input2 = Input(label="密码", placeholder="请输入密码", password_mode=True)
        
        grid_layout.addWidget(QLabel("用户名:"), 0, 0)
        grid_layout.addWidget(self.input1, 0, 1)
        grid_layout.addWidget(QLabel("密码:"), 1, 0)
        grid_layout.addWidget(self.input2, 1, 1)
        
        layout.addWidget(grid_widget)
        
        # 添加显示标签
        self.display_label = QLabel("输入内容将显示在这里")
        self.display_label.setAlignment(Qt.AlignCenter)
        layout.addWidget(self.display_label)
        
        # 连接信号
        self.input1.textChanged.connect(self.on_text_changed)
        self.input2.textChanged.connect(self.on_text_changed)
    
    def on_text_changed(self, text):
        """文本变化处理"""
        sender = self.sender()
        if sender == self.input1:
            self.display_label.setText(f"用户名: {text}")
        elif sender == self.input2:
            self.display_label.setText(f"密码: {text}")

if __name__ == "__main__":
    app = QApplication(sys.argv)
    
    # 设置应用样式
    app.setStyleSheet(Theme().get_style_sheet())
    
    window = TestWindow()
    window.show()
    
    sys.exit(app.exec_()) 